package com.itheima.reggie.interceptor;

import com.itheima.reggie.entity.Employee;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Slf4j
@Component
public class ProjectInterceptor implements HandlerInterceptor {

    @Override
    //true放行，false终止
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        log.info("[》》》SpringBoot拦截器]:--启动中-------------------");
//        //属性名称--->employee
//        HttpSession session = request.getSession();
//        Employee employee = (Employee)session.getAttribute("employee");
//        if(employee==null){
//            //返回登录界面
//            log.info("[》》》SpringBoot拦截器]:--不通过-------------------");
//            response.sendRedirect("http://localhost:8080/backend/page/login/login.html");
//            return false;
//        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
